﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="true" CodeFile="rptHistoryTransaction.aspx.cs" Inherits="reports_Transaction_rptHistoryTransaction" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>

    <script type="text/javascript">
        $(document).ready(function () {

            var date = new Date();
            var currentMonth = date.getMonth();
            var currentDate = date.getDate();
            var currentYear = date.getFullYear();
            var ok = true;
            var tgl = true;

            // format tanggal dengan datepicker
            $("#<%= txtPeriodeAwal.ClientID %>").attr('disabled', 'disabled');
            $("#<%= txtPeriodeAkhir.ClientID %>").attr('disabled', 'disabled');
            $("#<%= txtPeriodeAwal.ClientID %>").val('Periode Awal ');
            $("#<%= txtPeriodeAkhir.ClientID %>").val('Periode Akhir');
            $("#<%= rbPeriode2.ClientID %>").click(function () {
                $("#<%= txtPeriodeAwal.ClientID %>").attr('disabled', 'disabled');
                $("#<%= txtPeriodeAkhir.ClientID %>").attr('disabled', 'disabled');
                tgl = true;
                $("#<%= txtPeriodeAwal.ClientID %>").val('');
                $("#<%= txtPeriodeAkhir.ClientID %>").val('');
                $("#<%= txtPeriodeAwal.ClientID %>").val('Periode Awal ');
                $("#<%= txtPeriodeAkhir.ClientID %>").val('Periode Akhir');
            });
            $("#<%= rbPeriode1.ClientID %>").click(function () {
                $("#<%= txtPeriodeAwal.ClientID %>").removeAttr('disabled');
                $("#<%= txtPeriodeAkhir.ClientID %>").removeAttr('disabled');
                $("#<%= txtPeriodeAwal.ClientID %>").val('01/01/' + currentYear);
                $("#<%= txtPeriodeAkhir.ClientID %>").val(currentDate + '/' + parseInt((currentMonth) + 1) + '/' + currentYear);
                tgl = false;
            });
            $("#<%= txtPeriodeAwal.ClientID  %>").focus(function () {
                ok = false;
                tgl = false;
            });
            $("#<%= txtPeriodeAkhir.ClientID  %>").focus(function () {
                ok = false;
                tgl = false;
            });
            $("#<%= txtPeriodeAwal.ClientID  %>").datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy',
                numberOfMonths: 1,
                onSelect: function (selected) {
                    $("#<%= txtPeriodeAkhir.ClientID %>").datepicker("option", "minDate", selected)
                }
            });

            $("#<%= txtPeriodeAkhir.ClientID  %>").datepicker({ showWeek: true, showButtonPanel: true,
                changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy',
                numberOfMonths: 1,
                onSelect: function (selected) {
                    $("#<%= txtPeriodeAwal.ClientID %>").datepicker("option", "maxDate", selected)
                }
            });

            var IsLoad = true;


            var handleUrl = 'nothing'; //agar saat load data tidak muncul
            $('#table').jqGrid({
                url: handleUrl + '?method=getdatahistoryreport&periodeawal=&periodeakhir=',
                datatype: 'json',
                colNames: ['Tanggal Transaksi', 'No Transaksi', 'Jenis Transaksi', 'Keterangan', 'Debet (Rp)', 'Kredit (Rp)'],
                colModel: [
           		{ name: 'recBilling.BillingDate', index: 'BILLINGDATE', align: 'center', searchoptions: { sopt: ['eq', 'cn'] }, width: 115, formatter: 'date', formatoptions: { newformat: 'd M Y'} },
           		{ name: 'recBilling.BillingNo', index: 'INVOICEDATE', align: 'center', searchoptions: { sopt: ['eq', 'cn'] }, width: 200 },
                { name: 'recTransactionType.TransTypeName', index: 'TRANSTYPENAME', align: 'center', searchoptions: { sopt: ['eq', 'cn'] }, width: 140 },
                { name: 'recBilling.ForPayment', index: 'FORPAYMENT', align: 'left', searchoptions: { sopt: ['eq', 'cn'] }, width: 400 },
                { name: 'recBilling.PaymentValue', index: 'VALUE', align: 'right', searchoptions: { sopt: ['eq', 'cn'] }, width: 200, formatter: 'number' },
                { name: 'PaymentValue', index: 'PAYMENTVALUE', align: 'right', searchoptions: { sopt: ['eq', 'cn'] }, width: 200, formatter: 'number' },
                         	],
                rowNum: 10,
                id: 'recBilling.BillingDate',
                multiselect: true,
                rowList: [5, 10, 15, 20],
                pager: '#pager',
                sortname: 'recBilling.BillingDate',
                sortorder: "asc",
                viewrecords: true,
                jsonReader: { repeatitems: false },
                width: 1200,
                height: '100%',
                caption: 'Histori Transaksi',
                ajaxGridOptions: { cache: false },
                ondblClickRow: function () {
                    //                OpenForm('edit');
                }
            });

            //            $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, refreshtext: 'Refresh' },
            //        {}, {}, {}, { closeOnEscape: true, closeAfterSearch: true });



            $("#btnPrint").click(function () {


                if (jQuery("#table").jqGrid('getGridParam', 'records') > 0) {
                    if (ok == true && tgl == true) {
                        var formUrl = '<%= ResolveUrl("~/reports/Transaction/rptHistoryTransactionViewer.aspx") %>';
                        var periodeawal = $("#<%= txtPeriodeAwal.ClientID %>").val();
                        var periodeakhir = $("#<%= txtPeriodeAkhir.ClientID %>").val();
                        if (periodeawal.toString().toLowerCase().indexOf('awal') > -1 && periodeakhir.toString().toLowerCase().indexOf('akhir') > -1 && tgl == true) {
                            window.open(formUrl + "?periodeAwal=&periodeAkhir=");
                        }
                        else {
                            if (periodeawal.toString() != "" && periodeakhir.toString() != "") {
                                window.open(formUrl + "?periodeAwal=" + periodeawal + "&periodeAkhir=" + periodeakhir);
                            }
                            else {
                                alert('Periode tanggal tidak valid !')
                            }
                        }
                    }
                    else {
                        alert("Tekan submit terlebih dahulu !");
                    }
                }
                else {
                    alert("Data kosong tidak dapat di cetak !");
                }
            });

            $("#btnSubmit").click(function () {
                ok = true;
             //   alert(ok);
             //   alert(tgl);
                var periodeawal = $("#<%= txtPeriodeAwal.ClientID %>").val();
                var periodeakhir = $("#<%= txtPeriodeAkhir.ClientID %>").val();
                if (tgl == false) {
                    if (periodeawal.toString().toLowerCase().indexOf('awal') < 0 && periodeakhir.toString().toLowerCase().indexOf('akhir') < 0 && (periodeawal != "" && periodeakhir != "")) {
                        tgl = true;
                        jQuery("#table").setGridParam({ url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recInvoicehandler.ashx") %>' + '?method=getdatahistoryreport&periodeawal=' + periodeawal + '&periodeakhir=' + periodeakhir });
                        jQuery("#table").trigger("reloadGrid", [{ page: 1}]);

                    }
                    else {
                        alert('Periode tanggal tidak valid !');
                    }
                }
                else {
                    if (periodeawal.toString() != "" && periodeakhir.toString() != "" && tgl == true && (periodeawal.toString().toLowerCase().indexOf('2') < 0 && periodeakhir.toString().toLowerCase().indexOf('2') < 0)) {
                        //  tgl == true;
                        jQuery("#table").setGridParam({ url: '<%= ResolveUrl("~/AjaxHandler/Transaction/recInvoicehandler.ashx") %>' + '?method=getdatahistoryreport&periodeawal=&periodeakhir=' });
                        jQuery("#table").trigger("reloadGrid");
                    }
                    else if (periodeawal.toString().toLowerCase().indexOf('2') < 0 && periodeakhir.toString().toLowerCase().indexOf('2') < 0) {
                        alert('Periode tanggal tidak valid !');
                    }
                }
            });

        });
    </script>
<table border="0">
<tr>
            <td style="width: 43px; text-align: left; height: 17px;">
           
                        Periode
                    </td>
            <td style="height: 17px; width: 15px;">
                        :
                    </td>
            <td rowspan="2">
                <asp:RadioButton ID="rbPeriode1" runat="server" GroupName="rbPeriode" />
                <asp:TextBox ID="txtPeriodeAwal" runat="server" Width="150"></asp:TextBox>
                s/d
                        <asp:TextBox ID="txtPeriodeAkhir" runat="server" Width="150"></asp:TextBox>
                <br />
                <br />
                <asp:RadioButton ID="rbPeriode2" runat="server" GroupName="rbPeriode" 
                    Text="Semua" Checked="True" />
            </td>
        </tr>
<tr>
            <td style="width: 43px; text-align: left; height: 17px;">
           
                        &nbsp;</td>
            <td style="height: 17px; width: 15px;">
                        &nbsp;</td>
        </tr>
        </table>
        <br />
     <button class="dialog_link ui-state-default ui-corner-all" id="btnSubmit" type="button">
                        Lanjut
                    </button>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0""  >
    
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
    
     <button class="dialog_link ui-state-default ui-corner-all" id="btnPrint" type="button">
                        Cetak
                    </button>
   
</asp:Content>

